Code written for Direct Code Injection must be a syntactically-valid Groovy Class with a method called "execute()" with this signature:
public String execute (Map inParameters)
This method is invoked by N4 upon receipt of a JMS message as described below. The Map "inParameters" will contain name-value pairs of parameters that are supplied in the JMS message. Each parameter must be a String.
For convenience, there is a base class GroovyInjectionBase that the customer's Groovy code can extend that provides common API's into N4. Here is a first cut at the code that would be needed for the Stuff Automobile function:
import com.Navis.apex.business.model.GroovyInjectionBase
import com.Navis.argo.business.atoms.EventEnum
import com.Navis.argo.business.atoms.LocTypeEnum
import com.Navis.argo.business.model.CarrierVisit
import com.Navis.argo.business.reference.RoutingPoint
/*
* Prototype for Matson
*
* Copyright (c) 2007 Navis LLC. All Rights Reserved.
* $Id: StuffAutomobile.groovy,v 1.1 2008/02/16 00:26:36 shields Exp $
*/
class StuffAutomobile extends GroovyInjectionBase {
public String execute(Map inParameters) {
def ctrId = inParameters.get("equipment-id");
// Find the empty UFV
def emptyUfv = findActiveUfv(ctrId);
// Stuff it, and get back the new full UFV and Unit
def stuffedUfv = stuffUfv(emptyUfv, null);
def stuffedUnit = stuffedUfv.getUfvUnit();
// Update the routing
def carrierModeId = (String) inParameters.get("routing-carrier-mode");
def carrierId = (String) inParameters.get("routing-carrier-id");
def pod1Id = (String) inParameters.get("routing-pod-1");
def polId = (String) inParameters.get("routing-pol");
def destination = (String) inParameters.get("routing-destination");
def carrierMode = LocTypeEnum.getEnum(carrierModeId);
def obCarrier = CarrierVisit.findCarrierVisit(getFacility(), carrierMode, carrierId);
stuffedUfv.updateObCv(obCarrier);
def routing = stuffedUnit.getUnitRouting();
routing.setRtgDeclaredCv(obCarrier);
routing.setRtgPOD1(RoutingPoint.findRoutingPoint(pod1Id));
routing.setRtgPOL(RoutingPoint.findRoutingPoint(polId));
stuffedUnit.updateUnitRouting(routing);
stuffedUnit.getUnitGoods().setGoodsDestination(destination);
// Update the hazardous info
def hazardItem = stuffedUnit.getUnitGoods().attachHazard("3", "1203");
hazardItem.setHzrdiPageNumber("52");
// Record an event
stuffedUnit.recordUnitEvent(EventEnum.UNIT_STUFF, null, "stuffed");
return "done via Groovy, unit is: " + stuffedUnit;
}
}